package game;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Vector;

import util.INIGroup;

public class TileSet implements Loadable {
	private Vector<String> map1 = null;
	private Vector<String> map2 = null;
	private HashMap<String, Tile> tmap = null;
	private String tag = "";
	
	@Override
	public boolean loadFromFile(INIGroup grupa) {
		Enumeration<String> keys = grupa.vals.keys();
		map1 = new Vector<String>();
		map2 = new Vector<String>();
		while(keys.hasMoreElements())
		{
			String s = keys.nextElement();
			if("Tag".equals(s))
			{
				tag = grupa.vals.get(s);
			}
			else
			{
				map1.add(s);
				map2.add(grupa.vals.get(s));
				//map.put(s, grupa.vals.get(s));
			}
		}
		return true;
	}

	public String getTag()
	{
		return tag;
	}

	@Override
	public void init() {
		tmap = new HashMap<String, Tile>();
		for(int i = 0; i < map1.size(); ++i)
		{
			Tile t = GameBase.getTileByTag(map2.get(i));
			if(t != null)
				tmap.put(map1.get(i), t);
			else
				System.out.println("Error, tile \"" + map2.get(i) + "\" not found!");
		}
	}
	
	public Tile getTile(String s)
	{
		if(tmap == null)
			return null;
		return tmap.get(s);
	}
}
